var express = require('express');
var router = express.Router();
var products = require('../data/products');


function isMobile(req) {
    var deviceAgent = req.headers["user-agent"].toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
    return agentID;
}

/* GET home page. */
router.get('/', function(req, res, next) {
  var _isMobile = isMobile(req);
  res.render(_isMobile ?'mobile/index':'index', { title: '羅怡和-传承好味道，精致客家风情糕点' });
});

/*
*月饼列表页面-手机页面
*/
router.get('/mooncake-list', function(req, res, next) {
    res.render('mobile/mooncake-list', { title: '羅怡和月饼' });
});

router.get('/culture', function(req, res, next) {
    res.render('culture', { title: '羅怡和-品牌文化' });
});

router.get('/list', function(req, res, next) {
    var catagory = req.query['cata'] || '';
    /**
    * 精装礼盒 gift
    * 月饼 mooncake
    * 糕点 pastry
    * 饼 cookie0
    * 糖果 candy/halva
    * 米花糖 rice candy
    * */
    res.render('list', { title: '羅怡和-产品列表',catagory:'月饼' });
});

router.get('/detail',function(req, res, next) {
    var id = 'id_' + req.query['id'] || '';
    var product = products[id];
    res.render('detail', { title: product.name + '-产品详情',product: product })
});

router.get('/productCenter',function(req, res, next) {
    res.render('productCenter', { title: '美食中心'})
})

router.get('/taobaoChange',function(req, res, next) {
    res.render('taobaoChange', { title: '淘宝跳转'})
})

module.exports = router;